#include"Blockqueue.hpp"
#include"Task.hpp"
#include<iostream>
#include<pthread.h>
#include<unistd.h>
void *consumer(void*args)
{
    Blockqueue<task_t>*bq=static_cast<Blockqueue<task_t>*>(args);
    while(1)
    {
        sleep(10);
        //1.消费任务
        task_t t=bq->Pop();
        //2.处理任务
        t();
    }
}
void * productor(void*args)
{
    Blockqueue<task_t>*bq=static_cast<Blockqueue<task_t>*>(args);
    while(1)
    {
        cout<<"生产任务开始了"<<endl;
        bq->Equeue(Download);
    }
}
int main()
{
    Blockqueue<task_t>*bq=new Blockqueue<task_t>();
    pthread_t c[2],p[3];
     pthread_create(c, nullptr, consumer, bq);
    pthread_create(c+1, nullptr, consumer, bq);
    pthread_create(p, nullptr, productor, bq);
    pthread_create(p+1, nullptr, productor, bq);
    pthread_create(p+2, nullptr, productor, bq);

    pthread_join(c[0], nullptr);
    pthread_join(c[1], nullptr);
    pthread_join(p[0], nullptr);
    pthread_join(p[1], nullptr);
    pthread_join(p[2], nullptr);
    return 0;
}